package com.sh.data.engine.application.model.mapper.integration;


import com.sh.data.engine.application.model.request.integration.DataSourceCreateRequest;
import com.sh.data.engine.domain.integration.datasource.model.param.*;
import org.springframework.stereotype.Service;

@Service
public class DSCreateUpdateImpl implements DataSourceCreateParamMapper {

    @Override
    public DataSourceSaveParam requestToParam(DataSourceCreateRequest request) {
        if (request == null) {
            return null;
        }

        DataSourceSaveParam dataSourceSaveParam = new DataSourceSaveParam();
        dataSourceSaveParam.setId(request.getId());
        dataSourceSaveParam.setDsName(request.getDsName());
        dataSourceSaveParam.setDsType(request.getDsType().name());
        dataSourceSaveParam.setDsLink(request.getDsConfig().getDsLink());
        dataSourceSaveParam.setDsDesc(request.getDsDesc());
        dataSourceSaveParam.setConnectionProperty(request.getDsConfig().getConnectionProperty());

        return dataSourceSaveParam;
    }

    @Override
    public DataSourceRdbmsSaveParam requestToCreateRdbmsParam(DataSourceCreateRequest request) {
        if (request == null) {
            return null;
        }

        DataSourceRdbmsSaveParam dataSourceRdbmsSaveParam = new DataSourceRdbmsSaveParam();
        dataSourceRdbmsSaveParam.setId(request.getId());
        dataSourceRdbmsSaveParam.setDsName(request.getDsName());
        dataSourceRdbmsSaveParam.setDsType(request.getDsType().name());
        dataSourceRdbmsSaveParam.setDsLink(request.getDsConfig().getDsLink());
        dataSourceRdbmsSaveParam.setDsDesc(request.getDsDesc());
        dataSourceRdbmsSaveParam.setConnectionProperty(request.getDsConfig().getConnectionProperty());
        dataSourceRdbmsSaveParam.setUsername(request.getDsConfig().getUsername());
        dataSourceRdbmsSaveParam.setPassword(request.getDsConfig().getPassword());
        dataSourceRdbmsSaveParam.setServer(request.getDsConfig().getServer());
        dataSourceRdbmsSaveParam.setPort(request.getDsConfig().getPort());
        dataSourceRdbmsSaveParam.setSchema(request.getSchema());
        dataSourceRdbmsSaveParam.setDbName(request.getDsConfig().getDbName());
        dataSourceRdbmsSaveParam.setOracleConnectionType(request.getDsConfig().getOracleConnectionType());

        return dataSourceRdbmsSaveParam;
    }

    @Override
    public DataSourceHiveSaveParam requestToCreateHiveParam(DataSourceCreateRequest request) {
        if (request == null) {
            return null;
        }

        DataSourceHiveSaveParam dataSourceHiveSaveParam = new DataSourceHiveSaveParam();
        dataSourceHiveSaveParam.setId(request.getId());
        dataSourceHiveSaveParam.setDsName(request.getDsName());
        dataSourceHiveSaveParam.setDsType(request.getDsType().name());
        dataSourceHiveSaveParam.setDsLink(request.getDsConfig().getDsLink());
        dataSourceHiveSaveParam.setDsDesc(request.getDsDesc());
        dataSourceHiveSaveParam.setConnectionProperty(request.getDsConfig().getConnectionProperty());
        dataSourceHiveSaveParam.setUsername(request.getDsConfig().getUsername());
        dataSourceHiveSaveParam.setPassword(request.getDsConfig().getPassword());
        dataSourceHiveSaveParam.setServer(request.getDsConfig().getServer());
        dataSourceHiveSaveParam.setPort(request.getDsConfig().getPort());
        dataSourceHiveSaveParam.setDbName(request.getDsConfig().getDbName());
        dataSourceHiveSaveParam.setHiveSiteAddress(request.getDsConfig().getHiveSiteAddress());
        dataSourceHiveSaveParam.setOriginalFilename(request.getDsConfig().getOriginalFilename());

        return dataSourceHiveSaveParam;
    }

    @Override
    public DataSourceMongoSaveParam requestToCreateMongoParam(DataSourceCreateRequest request) {
        if (request == null) {
            return null;
        }

        DataSourceMongoSaveParam dataSourceMongoSaveParam = new DataSourceMongoSaveParam();
        dataSourceMongoSaveParam.setId(request.getId());
        dataSourceMongoSaveParam.setDsName(request.getDsName());
        dataSourceMongoSaveParam.setDsType(request.getDsType().name());
        dataSourceMongoSaveParam.setDsLink(request.getDsConfig().getDsLink());
        dataSourceMongoSaveParam.setDsDesc(request.getDsDesc());
        dataSourceMongoSaveParam.setConnectionProperty(request.getDsConfig().getConnectionProperty());
        dataSourceMongoSaveParam.setDbName(request.getDsConfig().getDbName());
        dataSourceMongoSaveParam.setUsername(request.getDsConfig().getUsername());
        dataSourceMongoSaveParam.setPassword(request.getDsConfig().getPassword());
        dataSourceMongoSaveParam.setAuthDbName(request.getDsConfig().getAuthDbName());
        dataSourceMongoSaveParam.setPort(String.valueOf(request.getDsConfig().getPort()));
        dataSourceMongoSaveParam.setServer(request.getDsConfig().getServer());

        return dataSourceMongoSaveParam;
    }

    @Override
    public DataSourceHDFSSaveParam requestToCreateHDFSParam(DataSourceCreateRequest request) {
        if (request == null) {
            return null;
        }

        DataSourceHDFSSaveParam dataSourceHDFSSaveParam = new DataSourceHDFSSaveParam();
        dataSourceHDFSSaveParam.setId(request.getId());
        dataSourceHDFSSaveParam.setDsName(request.getDsName());
        dataSourceHDFSSaveParam.setDsType(request.getDsType().name());
        dataSourceHDFSSaveParam.setDsLink(request.getDsConfig().getDsLink());
        dataSourceHDFSSaveParam.setDsDesc(request.getDsDesc());
        dataSourceHDFSSaveParam.setHdfsUser(request.getDsConfig().getHdfsUser());
        dataSourceHDFSSaveParam.setServer(request.getDsConfig().getServer());
        dataSourceHDFSSaveParam.setPort(request.getDsConfig().getPort());
        dataSourceHDFSSaveParam.setConnectionProperty(request.getDsConfig().getConnectionProperty());

        return dataSourceHDFSSaveParam;
    }

    @Override
    public DataSourceIotDBSaveParam requestToCreateIotDBParam(DataSourceCreateRequest request) {
        if (request == null) {
            return null;
        }

        DataSourceIotDBSaveParam dataSourceIotDBSaveParam = new DataSourceIotDBSaveParam();
        dataSourceIotDBSaveParam.setId(request.getId());
        dataSourceIotDBSaveParam.setDsName(request.getDsName());
        dataSourceIotDBSaveParam.setDsType(request.getDsType().name());
        dataSourceIotDBSaveParam.setDsLink(request.getDsConfig().getDsLink());
        dataSourceIotDBSaveParam.setDsDesc(request.getDsDesc());
        dataSourceIotDBSaveParam.setConnectionProperty(request.getDsConfig().getConnectionProperty());
        dataSourceIotDBSaveParam.setUsername(request.getDsConfig().getUsername());
        dataSourceIotDBSaveParam.setPassword(request.getDsConfig().getPassword());
        dataSourceIotDBSaveParam.setServer(request.getDsConfig().getServer());

        return dataSourceIotDBSaveParam;
    }

    @Override
    public DataSourceInfluxDBSaveParam requestToCreateInfluxDBParam(DataSourceCreateRequest request) {
        if (request == null) {
            return null;
        }

        DataSourceInfluxDBSaveParam dataSourceInfluxDBSaveParam = new DataSourceInfluxDBSaveParam();
        dataSourceInfluxDBSaveParam.setId(request.getId());
        dataSourceInfluxDBSaveParam.setDsName(request.getDsName());
        dataSourceInfluxDBSaveParam.setDsType(request.getDsType().name());
        dataSourceInfluxDBSaveParam.setDbName(request.getDsConfig().getDbName());
        dataSourceInfluxDBSaveParam.setDsLink(request.getDsConfig().getDsLink());
        dataSourceInfluxDBSaveParam.setDsDesc(request.getDsDesc());
        dataSourceInfluxDBSaveParam.setConnectionProperty(request.getDsConfig().getConnectionProperty());
        dataSourceInfluxDBSaveParam.setApiToken(request.getDsConfig().getApiToken());
        dataSourceInfluxDBSaveParam.setServer(request.getDsConfig().getServer());
        dataSourceInfluxDBSaveParam.setOrgName(request.getDsConfig().getOrgName());

        return dataSourceInfluxDBSaveParam;
    }
}
